//两个数组的交集，熟悉hashSet的使用
import java.util.Arrays;
import java.util.HashSet;

//练习hashSet
public class intersectionHashSetUse {
    public HashSet intersection(Integer[] a,Integer[] b){
        HashSet<Integer> set = new HashSet<Integer>(Arrays.asList(a));//将a作为列表传入set中，作为初始化数据
        HashSet<Integer> res = new HashSet<>();//用来存放结果，方便去重
        for (Integer num:b){
            if(set.contains(num)){
                res.add(num);
            }
        }
        return res;
    }
    public static void main(String[] args) {
        Integer[] a = new Integer[]{1,2,3,4,5,6};
        Integer[] b = new Integer[]{4,5,6};
        var main= new intersectionHashSetUse();
        HashSet res = main.intersection(a,b);
        for (Object num:res){
            System.out.println(num);
        }

        Integer[] s = new Integer[10];
        for (Integer num:s){
            System.out.println(num);
        }
    }
}
